package me.learning.enumeration

import me.learning.enumeration.Margin.BOTTOM
import me.learning.enumeration.TrafficLightColor.{Red, TrafficLightColor, Yellow}

object Driver {

  def main(args: Array[String]): Unit = {
    println("x")

    println(BOTTOM, BOTTOM.id)

    // load Red
    val red = TrafficLightColor(0) // Calls Enumeration.apply
    println(red, red.id)
    println(doWhat(red))
    println(doWhat2(TrafficLightColor.Yellow))

    //打印出所有枚举
    Margin.values.foreach { v => println(v, v.id) }
  }

  def doWhat(color: TrafficLightColor) = {
    if (color == Red) "stop"
    else if (color == Yellow) "hurry up" else "go"
  }

  //使用match匹配
  def doWhat2(color: TrafficLightColor) = color match {
    case Red => "stop"
    case Yellow => "hurry up"
    case _ => "go"
  }
}
